package org.pms.demo.webservice.filter;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.pms.demo.webservice.content.PmsContent;
import org.pms.demo.webservice.dao.pms.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Created by laijianpeng on 17/10/17.
 */
public class SysUserFilter extends PathMatchingFilter {

    @Autowired
    private UserMapper userMapper;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {

        String username = (String) SecurityUtils.getSubject().getPrincipal();
        request.setAttribute(PmsContent.CURRENT_USER, userMapper.getUserByName(username));
        return true;
    }
}
